const cloud = require("@cloudbase/node-sdk");

const app = cloud.init({
    env: cloud.SYMBOL_CURRENT_ENV,
});

var db = app.database();
const _ = db.command
// 物品数据库
const ZXGoods = db.collection('ZX-Data')

// 获取openId云函数入口函数
exports.main = async (event, context) => {

    const api = event.api

    // const res = await db
    // .collection('ZX-Booth')
    // .aggregate()
    // .lookup({
    //   from: 'ZX-Data',
    //   localField: 'book',
    //   foreignField: 'title',
    //   as: 'bookList'
    // })
    // .end()

    if(api=='api-goods-detail'){
        if(event.data._id){
            const res = await ZXGoods.doc(event.data._id).get()
            return res.data[0]
        }
    }

    if(api=='api-goods-list'){
        // 
        return await ZXGoods.where({
            id: _.in(event.data.ids)
        }).get()
    }
    
};